package study.nzy.com.studydemo;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class RegisterActivity extends Activity {

    EditText et_account;
    EditText et_psd;
    EditText et_psd_check;
    TextView tv_register;

    SharedPreferences sp;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);

        sp = RegisterActivity.this.getSharedPreferences("user_info",Context.MODE_PRIVATE);

        et_account = findViewById(R.id.et_account);
        et_psd = findViewById(R.id.et_psd);
        et_psd_check = findViewById(R.id.et_psd_check);
        tv_register =findViewById(R.id.tv_register);

        tv_register.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String account = et_account.getText().toString();
                String psd = et_psd.getText().toString();
                String psdCheck = et_psd_check.getText().toString();
                if(psd.equals(psdCheck))
                {
                    Toast.makeText(getApplicationContext(),"注册成功",Toast.LENGTH_SHORT).show();
                    SharedPreferences.Editor editor = sp.edit();
                    editor.putString("username_register",account);
                    editor.putString("password_register",psd);
                    editor.commit();
                    finish();
                }else {
                    Toast.makeText(getApplicationContext(),"密码不一致,注册失败",Toast.LENGTH_SHORT).show();

                }
            }
        });
    }

    public void clickClose(View view) {
        Intent intent = new Intent();
        intent.putExtra("result","我是返回值");
        setResult(200,intent);
        finish();
    }
}
